<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取form 参数</title>
</head>
<body>
    <form id="myForm">
        <div>
            <label>
                姓名：
                <input type="text" name="name" placeholder="请输入姓名" />
            </label>
        </div>
        <div>
            <label>
                年龄：
                <input type="text" name="age" placeholder="请输入年龄" />
            </label>
        </div>
        <div>
            <button id="submit">提交</button>
        </div>
    </form>
    <script>

        //form submit 中止掉
        var formSubmit = document.querySelector('#myForm');
        // formSubmit.onsubmit = function (e) {
        //     return false;
        // }
        
        //点击提交
        var submitHandle = document.querySelector('#submit');
        submitHandle.onclick = function (e) {

            e.preventDefault();
            
            var data = new FormData(formSubmit);

            console.log(data);
            console.log(data.get('age'), "<--data.get('age')");
            console.log(data.get('name'));

            //ajax
        }
        
    </script>
</body>
</html>